import 'package:flutter/material.dart';
import 'package:net/model/profile_mo.dart';
import 'package:net/navigator/hi_navigator.dart';
import 'package:hi_base/view_util.dart';
import 'package:net/widget/hi_blur.dart';

// 增值服务
class BannerFitCard extends StatelessWidget {
  final List<BenefitMo> bennefitList;
  const BannerFitCard({Key key, @required this.bennefitList}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 10, right: 5, top: 15),
      child: Column(
        children: [
          _buildTitle(),
          _buildCardFitList(context),
        ],
      ),
    );
  }

// 标题
  _buildTitle() {
    return Container(
      padding: EdgeInsets.only(bottom: 10),
      child: Row(
        children: [
          Text(
            '增值服务',
            style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
          ),
          hiSpace(width: 10),
          Text(
            '我是文案xxxz',
            style: TextStyle(fontSize: 12, color: Colors.grey[600]),
          ),
        ],
      ),
    );
  }

  _buildCardFitList(BuildContext context) {
    var width = (MediaQuery.of(context).size.width -
            20 -
            (bennefitList.length - 1) * 5) /
        bennefitList.length;
    return Row(
      children: [
        // toList和toSet都支持解构 都可以用
        ...bennefitList.map((e) => _buildCard(context, e, width)).toList()
      ],
    );
  }

  _buildCard(BuildContext context, BenefitMo mo, double width) {
    return InkWell(
      onTap: () {
        if (mo.url.contains('http')) {
          HiNavigator.geInstance().openH5(mo.url);
        } else {
          copyC(mo.url);
        }
      },
      child: Padding(
        child: ClipRRect(
          borderRadius: BorderRadius.circular(5),
          child: Container(
            alignment: Alignment.center,
            width: width,
            height: 60,
            decoration: BoxDecoration(color: Colors.deepOrangeAccent),
            child: Stack(
              children: [
                Positioned(child: HBlur(sigma: 20)),
                Positioned.fill(
                    child: Center(
                  child: Text(
                    mo.name,
                    style: TextStyle(color: Colors.white54),
                    textAlign: TextAlign.center,
                  ),
                ))
              ],
            ),
          ),
        ),
        padding: EdgeInsets.only(right: 5, bottom: 7),
      ),
    );
  }
}
